package com.pipayshop.controller;

import com.pipayshop.domain.StoreCategoryTop;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.PhysicalStoreCategoryTopService;
import com.pipayshop.entity.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 实体店一级分类表 前端控制器
 * </p>
 *
 * @author nws
 * @since 2023-07-25
 */
@Api(value = "实体店一级分类",tags = "实体店一级分类")
@RestController
@RequestMapping("/pipayshopapi/store-category-top")
@Slf4j
public class PhysicalStoreCategoryTopController {
    @Resource
    private PhysicalStoreCategoryTopService categoryTopService;

    @GetMapping("getShopCategoryTopList")
    @ApiOperation("查询一级分类列表")
    public ResponseVO<List<StoreCategoryTop>> getShopCategoryTopList() {
        try {
            List<StoreCategoryTop> list = categoryTopService.getShopCategoryTopList();
            return ResponseVO.getSuccessResponseVo(list);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new BusinessException("get_category_list_failed");
        }
    }


    @PostMapping("deleteShopCategoryTopById/{categoryTopId}")
    @ApiOperation("根据分类id删除分类")
    public ResponseVO<Boolean> deleteShopCategoryTopById(@PathVariable String categoryTopId) {
        try {
            Boolean aBoolean = categoryTopService.deleteShopCategoryTopById(categoryTopId);
            return aBoolean ? ResponseVO.getSuccessResponseVo(null) : ResponseVO.getFalseResponseVo(null);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new BusinessException("delete_category_failed");
        }
    }
    @PostMapping("updateShopCategoryTopById")
    @ApiOperation("根据分类id修改分类")
    public ResponseVO<Boolean> updateShopCategoryTopById(@RequestBody StoreCategoryTop shopCategoryTop) {
        try {
            Boolean aBoolean = categoryTopService.updateShopCategoryTopById(shopCategoryTop);
            return aBoolean ? ResponseVO.getSuccessResponseVo(null) : ResponseVO.getFalseResponseVo(null);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new BusinessException("modify_category_failed");
        }
    }

}
